package aa;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class Ma {

	public static void main(String[] args) throws Exception {
		savePic(loadFile());
		
	}
	 public static void savePic(String fileString) {
		
         File file = new File("C:/Users/PC/Desktop/x.jpg");
         try{

             OutputStream os = new FileOutputStream(file);

             os.write(fileString.getBytes());

             os.flush();

             os.close();

         }catch(Exception e){
             e.printStackTrace();
         }



     }
	
	
	
	public static String loadFile(){
		String 	filePath="C:/Users/PC/Desktop/qq.jpg";
		File  file = new File(filePath);

        FileInputStream fis = null;
        ByteArrayOutputStream in = null;
        byte[] data = null ;

        try {
            fis = new FileInputStream(file);
            in = new ByteArrayOutputStream((int) file.length());

            byte[] buffer = new byte[1024];
            int len = -1;
            while ((len = fis.read(buffer)) != -1) {
                in.write(buffer, 0, len);
            }

            data = in.toByteArray() ;

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                    fis = null;
                }

                in.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
        return new String(data,0,data.length);
    }
}
